//
//  MHAuditTableViewCell.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/5/10.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHAuditTableViewCell.h"
#import "MHAuditItemViewModel.h"

@implementation MHAuditTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
//    [self.auditBtn setBackgroundImage:[UIImage yy_imageWithColor:MHColorFromHexString(@"#EB715D")] forState:0];
//    [self.auditBtn setBackgroundImage:[UIImage yy_imageWithColor:[UIColor clearColor]] forState:UIControlStateDisabled];
    
   
    
    
//    [self.auditBtn setTitle:@"通过" forState:UIControlStateNormal];
//    [self.auditBtn setTitle:@"已通过" forState:UIControlStateDisabled];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}


-(void)bindViewModel:(MHAuditItemViewModel *)viewModel
{
    self.nameLable.text = viewModel.model.nickName;
    [self.avterImageView yy_setImageWithURL:[NSURL URLWithString:viewModel.model.fullUserFace] placeholder:MHDefaultAvatar(MHDefaultAvatarTypeDefualt)];
    self.auditBtn.enabled = (viewModel.model.status == 4);
    self.timeLabel.text = viewModel.model.applyTime;
    @weakify(self);
    [RACObserve(viewModel.model, status)  subscribeNext:^(NSNumber *statusNum) {
        @strongify(self);
        NSString *auditString = @"";
        int status = [statusNum intValue];
        self.auditBtn.enabled = (viewModel.model.status == 4);
        switch (status) {
            case MHAuditStatusPass:
                auditString = @"已通过";
                break;
            case MHAuditStatusReject:
                auditString = @"不通过";
                break;
            case MHAuditStatusIgnore:
                auditString = @"忽略";
                break;
            case MHAuditStatusAuditing:
                auditString = @"查看";
                break;
            default:
                break;
        }
        [self.auditBtn setTitle:auditString forState:0];
        [self.auditBtn setTitle:auditString forState:UIControlStateDisabled];
        
        if (self.auditBtn.enabled) {
            self.auditBtn.borderColor = MHRedTextColor;
            self.auditBtn.borderWidth = 1;
            self.auditBtn.layer.cornerRadius = 5;
            self.auditBtn.layer.masksToBounds = YES;
//            self.auditBtn.titleLabel.textColor = MHRedTextColor;
            [self.auditBtn setTitleColor:MHRedTextColor forState:0];
        }else
        {
            self.auditBtn.borderColor = MHRedTextColor;
            self.auditBtn.borderWidth = 0;
            self.auditBtn.layer.cornerRadius = 5;
            self.auditBtn.layer.masksToBounds = YES;
//            self.auditBtn.titleLabel.textColor = MHMetionTextColor;
             [self.auditBtn setTitleColor:MHMetionTextColor forState:0];
        }
      
    }];
    
    
    
}
@end
